package com.cloudsigns.factorymanager2.project.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.project.adapter.DesignContactOrderListAdapter;
import com.cloudsigns.factorymanager2.project.bean.DesignTypeBean;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 设计联系单列表
 * Created by tony on 2017/12/12.
 */

public class DesignContactOrderListActivity extends Activity implements View.OnClickListener, ItemClickListener {
    private ImageView img_back;
    private TextView tv_title;
    private TextView btn_delete;
    private ListView lv;
    private DesignContactOrderListAdapter adapter;
    private List<DesignTypeBean> designTypeBeanList = new ArrayList<>();
    private int selectedPosition = -1;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_design_contact_order_list);

        init();
    }

    private void init() {
        img_back = findViewById(R.id.img_back);
        tv_title = findViewById(R.id.tv_title);
        btn_delete = findViewById(R.id.btn_delete);
        lv = findViewById(R.id.lv);


        tv_title.setText(getResources().getText(R.string.design_contct_order));
        img_back.setOnClickListener(this);
        btn_delete.setOnClickListener(this);


        designTypeBeanList.add(new DesignTypeBean("方案设计", false, 0));
        designTypeBeanList.add(new DesignTypeBean("投标设计", false, 1));
        designTypeBeanList.add(new DesignTypeBean("vi手册", false, 0));
        designTypeBeanList.add(new DesignTypeBean("操作手册", false, 0));
        adapter = new DesignContactOrderListAdapter(this);
        adapter.setData(designTypeBeanList);
        adapter.setItemClick(this);
        lv.setAdapter(adapter);
    }

    private void delete(){
        if(selectedPosition >= 0){

        }
    }

    @Override
    public void onClick(View view) {
        TextView tv;
        Intent mIntent;
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.btn_delete:
                delete();
                break;


        }
    }

    @Override
    public void itemClick(View view, int position) {
        DesignTypeBean bean = designTypeBeanList.get(position);
        if (!bean.isSelected()) {
            if (selectedPosition >= 0) {
                designTypeBeanList.get(selectedPosition).setSelected(false);
                selectedPosition = position;
                designTypeBeanList.get(selectedPosition).setSelected(true);
            } else if (selectedPosition < 0) {
                selectedPosition = position;
                designTypeBeanList.get(selectedPosition).setSelected(true);
            }
            btn_delete.setBackgroundResource(R.mipmap.btn_long_bg_blue);
            adapter.notifyDataSetChanged();
        }


    }
}
